public class ThreadDemo15 {
    //了解 线程安全问题
    static class Counter {
        public int count=0;
        public void increase() {
            count++;
        }
    }
    static Counter counter=new Counter();

    public static void main(String[] args) {
        // 创建两个线程，分别对 count 自增5w次
        Thread t1=new Thread() {
            @Override
            public void run() {
                for (int i = 0; i <5_0000; i++) {
                    counter.increase();
                }
            }
        };
        t1.start();

        Thread t2=new Thread() {
            @Override
            public void run() {
                for (int i = 0; i <5_0000; i++) {
                    counter.increase();
                }
            }
        };
        t2.start();

        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(counter.count);


    }
}
